home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: ua302aa@lrz-muenchen.de ()
- Newsgroups: comp.lang.c
- Subject: Re: Sorting a Binary File
- Date: 15 Apr 1996 08:57:53 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4kt32h$m2c@sparcserver.lrz-muenchen.de>
- References: <4krpuf$jfp@news1.sympatico.ca>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- Gisele Swinson <gisele.swinson@sympatico.ca> writes:
-
- >I have declared a structure as follows:
-
- >#define max 5
-
- >struct customer
- >{
- > int seatno;
- > char lastname[15];
- >} Customer[max];
-
- >I have also initialized the structure as the seat numbers 1-5 and the last
- >name as blank
-
- >for(pass=1; pass<max; pass++)
- > for(i = 0; i<max-1; i++)
-
- > if(Customer[i].lastname > Customer[i+1].lastname)
-
- This is perfectly valid code, but maybe it's not what you think it is.
- "Customer[i].lastname" will _always_ be less that "Customer[i+1].lastname",
- so no swapping will ever happen. To compare strings (not just addresses),
- use strcmp().
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-
-